/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package Base;

import java.awt.Graphics;
import java.util.ArrayList;
import java.util.Arrays;

/**
 *
 * @author atxy2k
 */
public class Polygon2D {
    
    protected ArrayList<Point> list;
    protected int centerX, centerY;
    protected float pixelSize;
    protected int layer;
    
    public Polygon2D(ArrayList<Point> list) {
        this.list = list;
    }
    public Polygon2D(ArrayList<Point> list, int layer) {
        this.list = list;
        this.layer = layer;
    }
    public Polygon2D(Point... array) {
        list.addAll(Arrays.asList(array));
    }
    public Polygon2D(int layer,Point... array) {
        list.addAll(Arrays.asList(array));
        this.layer = layer;
    }
    
    public void add(Point p){
        list.add(p);
    }
    public void setValues(int centerX, int centerY, float pixelSize){
        this.centerX = centerX;
        this.centerY = centerY;
        this.pixelSize = pixelSize;
    }
    public void paint(Graphics g){
        for (int i = 0; i < list.size()-1; i++) {
            g.drawLine(toFisicX(list.get(i).getX()), toFisicY(list.get(i).getY()), toFisicX(list.get(i+1).getX()), toFisicY(list.get(i+1).getY()));
        }
    }
    
    /**
     * 
     * @param x Coordenada x en real a transformar a fisica antes de dibujar
     * @return la coordenada X en fisica
     */
    protected int toFisicX(float x){
        return Math.round(centerX+x/pixelSize);
    }
    /**
     * 
     * @param y Coordenada y en real a transformar
     * @return La coordenada transformada a fisica
     */
    protected int toFisicY(float y){
        return Math.round(centerY-y/pixelSize);
    }
    
    
}
